/**
 * 2011-11-16下午8:52:14
 */
package dao;

import java.sql.SQLException;

import util.MysqlConn;
import bean.Goods;

/**
 * @author Baicai 新增商品的方法
 */
public class NewGoods {

	/**
	 * 插入一条商品信息
	 * 
	 * @param nameString
	 * @param sortString
	 * @param price
	 * @param pictureSpring
	 * @param inforString
	 * @param userid
	 * @return Goods
	 */
	public static Goods newGood(String nameString, String sortString,
			float price, String pictureSpring, String inforString, int userid) {

		MysqlConn.setSqlString("insert into goods values(NULL,'" + nameString
				+ "',1,'" + sortString + "'," + price
				+ ",date(now()),time(now()),'" + pictureSpring + "','"
				+ inforString + "'," + userid + ");");// 拼接字符串

		try {
			int flag = MysqlConn.selectLastDB();// 插入数据并获取最后一条数据的id

			Goods goods;
			goods = SelectOneGoods.getOneGoods(flag);// 根据id将此数据查询出来

			return goods;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MysqlConn.free();
		}
		return null;
	}
}
